﻿using PSDLib;
using PSDLib.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PSDClientService.Burn
{
    public class BurnJobQueue
    {
        private BurnContext context;
        public RecorderDevice Recorder { get; set; }

        public List<BurnJob> Jobs { get; set; }

        public bool Burning { get; set; }
        public bool CloseMedia { get; set; }
        public bool EjectMedia { get; set; }

        public BurnJobQueue(BurnContext ctx, RecorderDevice recorder)
        {
            context = ctx;
            Recorder = recorder;
            Burning = false;
            CloseMedia = false;
            EjectMedia = true;
            Jobs = new List<BurnJob>();
        }

        public void AddJob(BurnJob job)
        {
            Jobs.Add(job);
        }

        public void Burn()
        {
            if (Jobs.Count > 0)
            {
                var job = Jobs[0];

                int result = Recorder.DetectRecorder();

                if (result == (int)ResultCode.Success)
                {
                    Recorder.SeBurnJob(job);

                    Recorder.StartBurn(job.DVD.dvd_title + "-" + job.DVD.dvd_num, this.CloseMedia, this.EjectMedia);
                }
            }
        }
    }
}
